package com.songxian.wechatcompose

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.compose.foundation.layout.Column
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.ui.Modifier
import androidx.core.view.WindowCompat
import androidx.lifecycle.viewmodel.compose.viewModel
import com.songxian.wechatcompose.ui.Home
import com.songxian.wechatcompose.ui.HomeBottomBar
import com.songxian.wechatcompose.ui.theme.WeTheme

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        WindowCompat.setDecorFitsSystemWindows(window, false)
        setContent {
            val viewModel: WeViewModel by viewModels()
            WeTheme(viewModel.theme) {
                Home()
            }
        }
    }

    override fun onBackPressed() {
        val viewModel: WeViewModel by viewModels()
        if (viewModel.currentChat != null) {
            viewModel.endChat()
        } else {
            super.onBackPressed()
        }
    }
}

